// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.commands.serverCommands;

import zombie.commands.AltCommandArgs;
import zombie.commands.CommandArgs;
import zombie.commands.CommandBase;
import zombie.commands.CommandHelp;
import zombie.commands.CommandName;
import zombie.commands.CommandNames;
import zombie.commands.RequiredRight;
import zombie.core.logger.LoggerManager;
import zombie.core.raknet.UdpConnection;
import zombie.network.GameServer;
import zombie.network.ServerOptions;
import zombie.network.ServerWorldDatabase;
import zombie.network.Userlog;

@CommandNames({@CommandName(
        name = "kick"
    ), @CommandName(
        name = "kickuser"
    )})
@AltCommandArgs({@CommandArgs(
        required = {"(.+)"}
    ), @CommandArgs(
        required = {"(.+)", "-r", "(.+)"}
    )})
@CommandHelp(
    helpText = "UI_ServerOptionDesc_Kick"
)
@RequiredRight(
    requiredRights = 56
)
public class KickUserCommand extends CommandBase {
    private String reason = "";

    public KickUserCommand(String username, String userAccessLevel, String command, UdpConnection connection) {
        super(username, userAccessLevel, command, connection);
    }

    @Override
    protected String Command() {
        String string = this.getCommandArg(Integer.valueOf(0));
        if (this.hasOptionalArg(Integer.valueOf(1))) {
            this.reason = this.getCommandArg(Integer.valueOf(1));
        }

        LoggerManager.getLogger("admin").write(this.getExecutorUsername() + " kicked user " + string);
        ServerWorldDatabase.instance.addUserlog(string, Userlog.UserlogType.Kicked, this.reason, this.getExecutorUsername(), 1);
        boolean _boolean = false;

        for (int int0 = 0; int0 < GameServer.udpEngine.connections.size(); int0++) {
            UdpConnection udpConnection = (UdpConnection)GameServer.udpEngine.connections.get(int0);

            for (int int1 = 0; int1 < 4; int1++) {
                if (string.equals(udpConnection.usernames[int1])) {
                    _boolean = true;
                    if ("".equals(this.reason)) {
                        GameServer.kick(udpConnection, "UI_Policy_Kick", null);
                    } else {
                        GameServer.kick(udpConnection, "You have been kicked from this server for the following reason: " + this.reason, null);
                    }

                    udpConnection.forceDisconnect("command-kick");
                    GameServer.addDisconnect(udpConnection);
                    break;
                }
            }
        }

        if (_boolean && ServerOptions.instance.BanKickGlobalSound.getValue()) {
            GameServer.PlaySoundAtEveryPlayer("RumbleThunder");
        }

        return _boolean ? "User " + string + " kicked." : "User " + string + " doesn't exist.";
    }
}
